package com.sofwin.service.impl;

import com.sofwin.mapper.SysMenuMapper;
import com.sofwin.pojo.SysMenu;
import com.sofwin.pojo.SysMenuExample;
import com.sofwin.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.awt.*;
import java.util.List;

/**
 * @packageName: com.sofwin.service.impl
 * @author: andyliu
 * @date: 2022/8/12 10:12
 * @email 115176513@qq.com
 * @description: TODO
 */
@Service("menuService")
public class MenuServiceImpl implements MenuService {
    @Autowired
    private SysMenuMapper mapper;

    @Override
    public boolean saveMenu(SysMenu menu) {
        if(menu.getId()!=null){
          return   mapper.updateByPrimaryKeySelective(menu)==1?true:false;
        }

        return mapper.insertSelective(menu)==1?true:false;
    }

    @Override
    public boolean removeById(Integer id) {
        return false;
    }

    @Override
    public boolean removeByIds(Integer[] ids) {
        return false;
    }

    @Override
    public SysMenu queryById(Integer id) {
        return null;
    }

    @Override
    public List<SysMenu> queryMenus(SysMenu menu) {
        SysMenuExample example = new SysMenuExample();
        SysMenuExample.Criteria criteria = example.createCriteria();
        if(!StringUtils.isEmpty(menu.getMenuName())){
            criteria.andMenuNameLike("%"+menu.getMenuName()+"%");
        }
        List<SysMenu> menus = mapper.selectByExample(example);
        return menus;
    }

    @Override
    public List<SysMenu> queryMenusByRoleId(Integer roleId) {
        return mapper.selectMenuByRoleId(roleId);
    }
}
